package Algorithm.Dp;

public class Leetcode152 {
    class Solution {
        public int maxProduct(int[] nums) {
            if(nums.length==1){
                return nums[0];
            }
            int max = nums[0];
            int min = nums[0];

            int mm = max;

            for(int i=1;i<nums.length;i++){
                int temp = max;
                max = Math.max(Math.max(min*nums[i],max*nums[i]),nums[i]);
                min = Math.min(Math.min(min*nums[i],temp*nums[i]),nums[i]);
                if(max>mm){
                    mm = max;
                }
            }

            return mm;
        }
    }
}
